import { BeforeInsert, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { BaseEntity } from './base.entity';
import * as bcrypt from 'bcryptjs';

/**
 * 用户
 */
@Entity('user')
export default class User extends BaseEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ comment: '账号' })
  username: string;

  @Column({ comment: '密码' })
  password: string;

  @Column({ comment: '昵称' })
  nickname: string;

  @Column({ comment: '头像' })
  avatar: string;

  @Column({ comment: '角色' })
  role: string;

  @Column({ name: 'enable_status', default: 1, comment: '启用状态' })
  enableStatus: number;

  @BeforeInsert()
  async encryptPwd() {
    this.password = await bcrypt.hashSync(this.password);
  }
}
